package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.api.vo.LogiLineStationVo;
import com.piggy.logi.sys.bo.LogiLineStationEditBo;
import com.piggy.logi.sys.bo.LogiLineStationQueryBo;
import com.piggy.logi.sys.service.ILogiLineStationService;
import com.piggy.logi.sys.api.vo.LogiLineStationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 线路站点管理Controller
 *
 * @author piggy
 * @date 2023-08-14
 */
@Api(value = "线路站点管理控制器", tags = {"线路站点管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/linestation")
public class LogiLineStationController extends BaseController {

    private final ILogiLineStationService iLogiLineStationService;

    /**
     * 查询线路站点管理列表
     */
    @ApiOperation("查询线路站点管理列表")
    //@SaCheckPermission("sys:linestation:list")
    @GetMapping("/list")
    public TableDataInfo<LogiLineStationVo> list(@Validated LogiLineStationQueryBo bo) {
        return iLogiLineStationService.queryPageList(bo);
    }

    /**
     * 导出线路站点管理列表
     */
    @ApiOperation("导出线路站点管理列表")
    //@SaCheckPermission("sys:linestation:export")
    @LogiLog(title = "线路站点管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiLineStationQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiLineStationVo> list = iLogiLineStationService.queryList(bo);
        ExcelUtil<LogiLineStationVo> util = new ExcelUtil<LogiLineStationVo>(LogiLineStationVo.class);
        util.exportExcel(response, list, "线路站点管理");
    }

    /**
     * 获取线路站点管理详细信息
     */
    @ApiOperation("获取线路站点管理详细信息")
    //@SaCheckPermission("sys:linestation:query")
    @GetMapping("/{id}")
    public R<LogiLineStationVo> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable("id") Long id) {
        return R.ok(iLogiLineStationService.queryById(id));
    }

    /**
     * 新增线路站点管理
     */
    @ApiOperation("新增线路站点管理")
    //@SaCheckPermission("sys:linestation:add")
    @LogiLog(title = "线路站点管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Integer> add(@Validated @RequestBody LogiLineStationEditBo bo) {
        return R.ok(iLogiLineStationService.addByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改线路站点管理
     */
    @ApiOperation("修改线路站点管理")
    //@SaCheckPermission("sys:linestation:edit")
    @LogiLog(title = "线路站点管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Integer> edit(@Validated @RequestBody LogiLineStationEditBo bo) {
        return R.ok(iLogiLineStationService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除线路站点管理
     */
    @ApiOperation("删除线路站点管理")
    //@SaCheckPermission("sys:linestation:remove")
    @LogiLog(title = "线路站点管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        return R.ok(iLogiLineStationService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}